var _prmpt_window = null;
var _lock_div = null;
var _doc = null;

function init_prompt(doc, prmpt_wndw_id, prmpt_wndw_width, prmpt_wndw_height, lock_div_id) {
    if(typeof(doc) !== "undefined" && doc !== null) {
        _doc = doc;
    } else {
        alert("您指定的document为空！！！");
        return;
    }
    if(typeof(prmpt_wndw_id) === "undefined" || prmpt_wndw_id === null) {
        alert("您指定的弹出窗口不存在！！！");
        return;
    } else {
        _prmpt_window = _doc.getElementById(prmpt_wndw_id);
        if(typeof(_prmpt_window) === "undefined" || _prmpt_window === null) {
            alert("您指定的弹出窗口不存在！！！");
            return;
        } 
    }
    
    if(typeof(lock_div_id) !== "undefined" && lock_div_id !== null) {
        _lock_div = _doc.getElementById(lock_div_id);
        if(typeof(_lock_div) === "undefined" && _lock_div === null) {
            _lock_div = null;
        }
    }
    prompt_lock_div1();
    prompt_window1(prmpt_wndw_width, prmpt_wndw_height);
}

//弹出锁定层
function prompt_lock_div(lock_div_id, doc) {
	var doc0 =  document;
	if(doc !== null && typeof(doc) !== "undefined") {
        doc0 = doc;
    }
	alert(doc0.getElementById(lock_div_id));
    prompt_lock_div0(doc0.getElementById(lock_div_id), doc0);
}
function prompt_lock_div1() {
    prompt_lock_div0(_lock_div, _doc);
}
function prompt_lock_div0(lock_div, doc) {
    if(lock_div === null || typeof(lock_div) === "undefined") {
        alert("您指定的锁定层不存在！！！");
        return;
    }
    var tWidth = doc.body.scrollWidth;
    var tHeight = doc.body.scrollHeight;
    if(lock_div !== null) {
        lock_div.style.display = "block";
        
        if (tWidth < doc.body.clientWidth) {
            tWidth = doc.body.clientWidth;
        }
        if (tHeight < doc.body.clientHeight) {
            tHeight = doc.body.clientHeight;
        }
        if(tHeight < doc.body.offsetHeight) {
            tHeight = doc.body.offsetHeight;
        }
        tHeight = tHeight + 10;
        lock_div.style.width = tWidth + "px";
        lock_div.style.height = tHeight + "px";
        lock_div.style.minWidth = tWidth + "px";
        lock_div.style.minHeight = tHeight + "px";
    }
}

//弹出操作层
function prompt_window(prmpt_wndw_id, prmpt_wndw_width, prmpt_wndw_height){
    var wndw = document.getElementById(prmpt_wndw_id);
    prompt_window0(wndw, prmpt_wndw_width, prmpt_wndw_height, document);
}
function prompt_window1(prmpt_wndw_width, prmpt_wndw_height) {
    prompt_window0(_prmpt_window, prmpt_wndw_width, prmpt_wndw_height, _doc);
}
function prompt_window0(prompt_window, prmpt_wndw_width, prmpt_wndw_height, doc) {
    if(prompt_window == null || typeof(prompt_window) === "undefined") {
        alert("您指定的弹出层不存在！！！");
        return;
    }
    var tWidth = doc.body.scrollWidth;
    var tHeight = doc.body.scrollHeight;
    if (tWidth < doc.body.clientWidth) {
        tWidth = doc.body.clientWidth;
    }
    if (tWidth < doc.body.offsetWidth) {
        tWidth = doc.body.offsetWidth;
    }
    if (tHeight < doc.body.clientHeight) {
        tHeight = doc.body.clientHeight;
    }
    if(tHeight < doc.body.offsetHeight) {
        tHeight = doc.body.offsetHeight;
    }
    tHeight = tHeight + 10;
    // 将弹出层垂直居中
    var pw_width = 300;
    var pw_height = 150;
    if(typeof(prmpt_wndw_width) !== "undefined" && prmpt_wndw_width !== null) {
        pw_width = prmpt_wndw_width;
    }
    if(typeof(prmpt_wndw_height) !== "undefined" && prmpt_wndw_height !== null) {
        pw_height = prmpt_wndw_height;
    }
    
    prompt_window.style.left = (tWidth - pw_width) / 2  + "px";
    prompt_window.style.top = GetPageScroll()["Y"] + ((window.screen.availHeight - pw_height)/2 - 100)+"px";
    prompt_window.style.display = "block";
    prompt_window.style.width = pw_width + "px";//设置弹出窗口的宽度
    prompt_window.style.height = pw_height + "px";//设置弹出窗口的高度
}

function close_prmpt(prmpt_wndw_id) {
    close_prmpt0(prmpt_wndw_id, document);
}

function close_prmpt0(prmpt_wndw_id, doc) {
    doc.getElementById(prmpt_wndw_id).style.display = "none";
}

function _close() {
   if(_prmpt_window !== null) {_prmpt_window.style.display = "none";}
   if(_lock_div !== null) {_lock_div.style.display = "none";}
}

function GetPageScroll() {
    var x, y;
    if(window.pageYOffset) {
        // all except IE
        y = window.pageYOffset;
        x = window.pageXOffset;
    } else if(document.documentElement && document.documentElement.scrollTop) {
        // IE 6 Strict
        y = document.documentElement.scrollTop;
        x = document.documentElement.scrollLeft;
    } else if(document.body) {
        // all other IE
        y = document.body.scrollTop;
        x = document.body.scrollLeft; 
    }
    return {X:x, Y:y};
}